﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TestServer
{
    public partial class ConnectionListForm : Form
    {
        private Dictionary<string, DataGridViewRow> _ConnectionRows = new Dictionary<string, DataGridViewRow>(16);

        public ConnectionListForm()
        {
            InitializeComponent();
        }

        public void AddConnectionRow(string id, string ip, string reliableQueueSize, string latency)
        {
            DataGridViewRow row = new DataGridViewRow();
            row.Cells.Add(new DataGridViewTextBoxCell() { Value = id });
            row.Cells.Add(new DataGridViewTextBoxCell() { Value = ip });
            row.Cells.Add(new DataGridViewTextBoxCell() { Value = reliableQueueSize });
            row.Cells.Add(new DataGridViewTextBoxCell() { Value = latency });
            ConnectionsGridView.Rows.Add(row);
            _ConnectionRows[id] = row;
        }

        public void RemoveConnectionRow(string id)
        {
            ConnectionsGridView.Rows.Remove(_ConnectionRows[id]);
            _ConnectionRows.Remove(id);
        }

        public void UpdateConnectionRow(string id, string reliableQueueSize, string latency)
        {
            DataGridViewRow row = _ConnectionRows[id];
            row.Cells[2].Value = reliableQueueSize;
            row.Cells[3].Value = latency;
        }
    }
}
